import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;

/**
 * 接口字段维护 /ciam/role/api/:roleId
 * SearchForm
 * @date 2019-07-10
 */
import React from 'react';
import { Button, Col, Form, Input, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Lov from 'components/Lov';
import cacheComponent from 'components/CacheComponent';
import intl from 'utils/intl';
import { VERSION_IS_OP } from 'utils/config';
import { isTenantRoleLevel } from 'utils/utils';
import { FORM_COL_4_LAYOUT, SEARCH_COL_CLASSNAME, SEARCH_FORM_CLASSNAME, SEARCH_FORM_ITEM_LAYOUT, SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
var expandFormStyle = {};
var noExpandFormStyle = {
  display: 'none'
};
var SearchForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = cacheComponent({
  cacheKey: '/ciam/role/api/search-form'
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(SearchForm, _React$Component);

  var _super = _createSuper(SearchForm);

  function SearchForm(props) {
    var _this;

    _classCallCheck(this, SearchForm);

    _this = _super.call(this, props);
    _this.state = {
      expandForm: false
    };
    return _this;
  }

  _createClass(SearchForm, [{
    key: "handleResetBtnClick",
    value: function handleResetBtnClick(e) {
      e.preventDefault();
      var form = this.props.form;
      form.resetFields();
    }
  }, {
    key: "handleSearchBtnClick",
    value: function handleSearchBtnClick(e) {
      e.preventDefault();
      var onSearch = this.props.onSearch;
      onSearch();
    }
  }, {
    key: "handleToggleForm",
    value: function handleToggleForm() {
      var _this$state$expandFor = this.state.expandForm,
          expandForm = _this$state$expandFor === void 0 ? false : _this$state$expandFor;
      this.setState({
        expandForm: !expandForm
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          form = _this$props.form,
          _this$props$requestMe = _this$props.requestMethod,
          requestMethod = _this$props$requestMe === void 0 ? [] : _this$props$requestMe;
      var _this$state$expandFor2 = this.state.expandForm,
          expandForm = _this$state$expandFor2 === void 0 ? false : _this$state$expandFor2;
      return /*#__PURE__*/React.createElement(Form, {
        className: SEARCH_FORM_CLASSNAME
      }, /*#__PURE__*/React.createElement(Row, Object.assign({
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.api.serviceName').d('服务名')
      }), form.getFieldDecorator('serviceName')( /*#__PURE__*/React.createElement(Lov, {
        allowClear: true,
        code: VERSION_IS_OP || isTenantRoleLevel() ? 'CADM.ROUTE.SERVICE_CODE.ORG' : 'CADM.ROUTE.SERVICE_CODE',
        textField: "serviceName"
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.api.method').d('请求方式')
      }), form.getFieldDecorator('method')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, requestMethod.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.api.path').d('请求路径')
      }), form.getFieldDecorator('path')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleToggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get('cpaas.common.button.viewMore').d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleResetBtnClick
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        htmlType: "submit",
        type: "primary",
        onClick: this.handleSearchBtnClick
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        style: expandForm ? expandFormStyle : noExpandFormStyle
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.roleManagement.model.api.description').d('请求描述')
      }), form.getFieldDecorator('description')( /*#__PURE__*/React.createElement(Input, null))))));
    }
  }]);

  return SearchForm;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "handleResetBtnClick", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleResetBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSearchBtnClick", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearchBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleToggleForm", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleToggleForm"), _class2.prototype)), _class2)) || _class) || _class);
export { SearchForm as default };